home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / INTERNET / SITES / GRAHAM / XAAES_S.ZIP / XAAES / BOOTUP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-06  |  18.2 KB  |  683 lines

  1. /*
  2.  * XaAES - XaAES Ain't the AES
  3.  *
  4.  * A multitasking AES replacement for MiNT
  5.  *
  6.  */
  7.  
  8. #include <VDI.H>
  9. #include <OSBIND.H>
  10. #include <MINTBIND.H>
  11. #include <UNISTD.H>
  12. #include <FILESYS.H>
  13. #include <SIGNAL.H>
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <ostruct.h>
  18. #include "xa_defs.h"
  19. #include "k_defs.h"
  20. #include "xa_types.h"
  21. #include "frm_alrt.h"
  22. #include "handler.h"
  23. #include "cookies.h"
  24. #include "kernal.h"
  25. #include "mouse_cl.h"
  26. #include "c_window.h"
  27. #include "std_widg.h"
  28. #include "XA_GLOBL.H"
  29. #include "system.h"
  30. #include "signals.h"
  31. #include "shellwrt.h"
  32. #include "resource.h"
  33. #include "objects.h"
  34. #include "about.h"
  35. #include "DESKTOP.H"
  36. #include "F_XBIOS.H"
  37.  
  38. /* aes.h confilcts with k_defs.h, so we can't use it here... :-( */
  39. #if defined(LATTICE)        /* ----- Lattice C ----- */
  40. extern short _AESglobal[15];
  41. #define global _AESglobal
  42. int __regargs _AESif(unsigned int);
  43. #define appl_init() _AESif(0)
  44. extern int graf_handle(short *,short *,short *,short *);
  45. #define appl_exit()    _AESif(36)
  46. #elif defined(__PUREC__)    /* ----- Pure C 1.1 ----- */
  47. typedef struct
  48. {
  49.     int        contrl[15];
  50.     int        global[15];
  51.     int        intin[132];
  52.     int        intout[140];
  53.     void    *addrin[16];
  54.     void    *addrout[16];
  55. } GEMPARBLK;
  56. extern  GEMPARBLK _GemParBlk;
  57. #define global _GemParBlk.global
  58. extern int appl_init(void);
  59. extern int graf_handle(int *,int *,int *,int *);
  60. extern int appl_exit(void);
  61. #else                        /* ----- others ----- */
  62. extern short global[] ;
  63. extern int appl_init(void) ;
  64. extern int graf_handle(int *,int *,int *,int *);
  65. extern int appl_exit(void);
  66. #endif
  67.  
  68. /*
  69.     Boot up code
  70. */
  71.  
  72. const char select_ink[]={27,'b',0};
  73. const char select_paper[]={27,'c',0};
  74.  
  75. void _XCEXIT(void)
  76. {
  77.     exit(0);
  78. }
  79.  
  80. void BootMessage(void)
  81. {
  82.     printf("XaAES ");
  83.     printf(XA_VERSION);
  84.     printf("\nMultiTasking AES for MiNT\n");
  85.     printf("(w)1995,96, Craig Graham, Johan Klockars, Martin Koehling, Thomas Binder\n");
  86.     printf("Date: %s\n",__DATE__);
  87.     printf("Compile time switches enabled:\n");
  88.  
  89. #if GENERATE_DIAGS
  90.     printf(" - Diagnostics\n");
  91. #endif
  92.  
  93. #if FORCE_WINDOWS
  94.     printf(" - Force windows\n");
  95. #endif
  96.  
  97. #if SOLID_BOXES
  98.     printf(" - Solid boxes\n");
  99. #endif
  100.  
  101. #if MONO_WIDGETS
  102.     printf(" - Mono widgets\n");
  103. #else
  104.     printf(" - Colour widgets\n");
  105. #endif
  106.         
  107. #if DISPLAY_LOGO_IN_TITLE_BAR
  108.     printf(" - Logo in title bar\n");
  109. #endif
  110.  
  111. #if POINT_TO_TYPE
  112.     printf(" - Point-to-type\n");
  113. #endif
  114.  
  115. #if ALT_CTRL_APP_OPS
  116.     printf(" - CTRL+ALT key-combo's\n");
  117. #endif
  118.  
  119. #if USE_CALL_DIRECT
  120.     printf(" - Use direct-call\n");
  121. #endif
  122.  
  123. #if AVOID_MINT_PIPES_BUG
  124.     printf(" - Avoid MiNT pipe delete bug\n");
  125. #endif
  126.  
  127. #if EMULATE_AES4_1
  128.     printf(" - Emulate AES4.1\n");
  129. #else
  130.     printf(" - Emulate AES1.4\n");
  131. #endif
  132.  
  133. #if DODGY_MEMORY_PROTECTION
  134.     printf(" - Dodgy OS_SPECIAL memory access\n");
  135. #endif
  136.  
  137. #if JOHAN_RECTANGLES
  138.     printf(" - Johan's new rectangle lists\n");
  139. #endif
  140.  
  141.     printf("\n");
  142. }
  143.  
  144. short P_handle=0,V_handle=0;        /* Workstation handles used by the AES */
  145. XA_SCREEN display;                    /* The display descriptor */
  146. const XA_COLOUR_SCHEME default_colours={LWHITE,BLACK,LBLACK,WHITE,BLACK,CYAN};
  147. const XA_COLOUR_SCHEME bw_default_colours={WHITE,BLACK,BLACK,BLACK,BLACK,BLACK};
  148. int AES_in_pipe;                    /* The AES instruction input pipe handle */
  149. unsigned long client_handle_mask=0L;    /* Mask of all active client pipes for Fselect */
  150.  
  151. int MOUSE_in_pipe;                    /* The MOUSE data packet input pipe handle */
  152.  
  153. long KBD_device;                    /* The MiNT keyboard device's file handle */
  154.  
  155. short AESpid;                        /* The AES's MiNT process ID */
  156.  
  157. XA_WINDOW *root_window;                /* The desktop window */
  158.  
  159. #if GENERATE_DIAGS
  160. char debug_path[100];                /* Path to dump debug info to */
  161. short debug_file;                    /* File handle to dump debug stuff to */
  162. #endif
  163.  
  164. char XaAES_home[200];                /* XaAES's home location */
  165. short XaAES_home_drv;
  166.  
  167. char scrap_path[128];                /* Path to the scrap directory */
  168. char acc_path[128];                    /* Path to desk accessory directory */
  169.  
  170. void *system_resources;                /* Pointer to the XaAES resources */
  171. const char dummy_cmd_tail[]="\0";     /* Dummy constants used for distinguishing */
  172. const char dummy_cmd_name[]="";     /* malloced from non-malloced strings... */
  173.  
  174. /* mode codes for falcon video mode switch */
  175. const short falcon_modes[]=    {0+0x8+0x10,1+0x8+0x10,2+0x8+0x10,3+0x8+0x10};
  176.  
  177. short iconify_x,iconify_y,iconify_w,iconify_h;    /* Positioning information for iconifying windows */
  178.  
  179. short mouse_pid;
  180.  
  181. /*
  182.     Read & parse the 'xaaes.cnf' file.
  183. */
  184. void parse_cnf(void)
  185. {
  186.     FILE *cnf;
  187.     char lb[210],parms[200],*p;
  188.     short tl,t;
  189.     
  190.     lb[202]='\0';
  191.     
  192.     cnf=fopen("xaaes.cnf","r");
  193.     if (!cnf)
  194.     {
  195.         cnf=fopen("u:\\c\\mint\\xaaes.cnf","r");
  196.         if (!cnf)
  197.         {
  198.             cnf=fopen("u:\\c\\multitos\\xaaes.cnf","r");
  199.             if (!cnf)
  200.             {
  201.                 cnf=fopen("u:\\c\\xaaes.cnf","r");
  202.                 if (!cnf)
  203.                 {
  204.                     DIAGS(("WARNING: Couldn't open xaaes.cnf\n"));
  205.                     return;
  206.                 }
  207.             }
  208.         }
  209.     }
  210.  
  211.     while(!feof(cnf))
  212.     {
  213.         fgets(lb,199,cnf);
  214.         
  215.         if (lb[0]!='#')                            /* '#' is a comment line */
  216.         {
  217.             tl=strlen(lb);
  218.             
  219.             for(t=0; (t<tl)&&(lb[t]!=' '); t++) 
  220.                 if ((lb[t]>96)&&(lb[t]<123))    /* Capitalise the command */
  221.                     lb[t]-=32;
  222.  
  223.             for(t++; t<tl; t++)
  224.             {
  225.                 if (lb[t]<14)                    /* Strip out unwanted carriage returns, etc */
  226.                     lb[t]='\0';
  227.             }
  228.             
  229.             if (!strncmp(lb,"RUN ",4))            /* Run command launches a program */
  230.             {
  231.                 for(p=lb+4; (*p!=' ')&&(*p!='\0'); p++);
  232.                 if (*p)
  233.                 {
  234.                     *p='\0';
  235.                     p++;
  236.                 }
  237.                 sprintf(parms+1,"%s",p);
  238.                 parms[0]=(char)strlen(parms+1);
  239.                 
  240.                 shell_write(0,0,0,lb+4,parms);
  241.             }
  242.             
  243.             if (!strncmp(lb,"CLIPBOARD ",10))    /* Set the location of the default clipboard */
  244.             {
  245.                 sprintf(scrap_path,"%s",lb+10);
  246.             }
  247.  
  248.             if (!strncmp(lb,"ACCPATH ",8))    /* Set the location of the default clipboard */
  249.             {
  250.                 sprintf(acc_path,"%s",lb+8);
  251.             }
  252.             
  253. #if GENERATE_DIAGS
  254.             if (!strncmp(lb,"DEBUG ",6))        /* Redirect console output */
  255.             {
  256.                 sprintf(debug_path,"%s",lb+6);
  257.             }
  258. #endif
  259.         }
  260.     }
  261. }
  262.  
  263. void load_accs(void)
  264. {
  265.     char search_path[200];
  266.     char acc[200];
  267.     short fnd;
  268.     _DTA *my_dta=Fgetdta();
  269.     
  270.     sprintf(search_path,"%s*.ACC",acc_path);
  271.  
  272.     fnd=Fsfirst(search_path,0xff);
  273.     while(!fnd)
  274.     {
  275.         sprintf(acc,"%s%s",acc_path,my_dta->dta_name);
  276.         shell_write(3,0,0,acc,"");
  277.         fnd=Fsnext();
  278.     }
  279. }
  280.  
  281. static short auto_program ;
  282.  
  283. /*
  284.     Cleanup on exit
  285.     - this is pretty iffy at the moment, but it will get you back to a command line.
  286.       (you cann't re-start XaAES again though :( )
  287. */
  288. static void Cleanup(void)
  289. {
  290.     XA_CLIENT *client;
  291.     long ex_con;
  292.     
  293.     DIAGS(("Cleaning up ready to exit....\n"));
  294.     Psignal(SIGCHLD, 0L);
  295.     
  296. /* Kill off clients */
  297.     for(client=FirstClient(); client!=NULL; client=NextClient(client))
  298.     {
  299.         if (client->clnt_pipe_rd)
  300.         {
  301.             DIAGS(("Killing:%d:%s:%s\n",Client2Pid(client),client->cmd_name,client->name));
  302.             Pkill(Client2Pid(client),SIGTERM);
  303.         }
  304.     }
  305.  
  306.     Syield();
  307.     
  308.     for(client=FirstClient(); client!=NULL; client=NextClient(client))
  309.     {
  310.         if (client->clnt_pipe_rd)
  311.         {
  312.             ex_con=Pwaitpid(Client2Pid(client),1,NULL);        /* if client ignored SIGTERM, send SIGKILL */
  313.             if (!ex_con)
  314.             {
  315.                 Pkill(Client2Pid(client),SIGKILL);
  316.             }
  317.         }
  318.     }
  319.  
  320. /* Kill off the mouse server */
  321.     DIAGS(("Killing mouse server\n"));
  322.     Pkill(mouse_pid,SIGTERM);    /* "Please die". This gives the server */
  323.                                         /* a chance to clean up before exiting; SIGKILL */
  324.                                         /* can't be caught! */
  325.  
  326.     /* Wait for mouse server to terminate; this is *essential*! */
  327.     /* It helps prevent two problems: */
  328.     /* - The XaAES kernal might close the physical screen workstation before */
  329.     /*   the mouse server is finished restoring the interrupt vectors. */
  330.     /* - If XaAES.TOS was started from the DESKTOP, GEM AES restores */
  331.     /*   the mouse button and mouse movement vectors afterwards; if this */
  332.     /*   happens *before* the mouse server is finished, this causes */
  333.     /*   problems... (e.g.: button clicks are no longer accepted) */
  334.     Pwaitpid(mouse_pid, 0, NULL);
  335.  
  336. /* Close screen workstation */
  337.     v_clsvwk(V_handle);
  338.     if ( auto_program )
  339.         v_clswk(P_handle);    /* Auto version must close the physical workstation */
  340.  
  341. /* Close the AES command pipe (server end) */
  342.     Fclose(AES_in_pipe);
  343.     
  344. /* Unhook from the trap vector */
  345.     unhook_from_vector() ;
  346.     
  347. /* Remove semaphores: */
  348.     Psemaphore(1,APPL_INIT_SEMAPHORE,0);
  349.     Psemaphore(1,TRAP_HANDLER_SEMAPHORE,0);
  350.     Psemaphore(1,WIN_LIST_SEMAPHORE,0);
  351.     Psemaphore(1,ROOT_SEMAPHORE,0);
  352.     Psemaphore(1,CLIENTS_SEMAPHORE,0);
  353.     Psemaphore(1,UPDATE_LOCK,0);
  354.     Psemaphore(1,MOUSE_LOCK,0);
  355.     if ( !auto_program )    /* If we weren't an auto program, call appl_exit() to the standard AES */
  356.         appl_exit() ;
  357. }
  358.  
  359.  
  360. /*
  361.     Startup & Initialisation....
  362.     - Spawn off any extra programs we need (mouse server, etc).
  363.     - Open physical & virtual workstations.
  364.     - Install our trap handler.
  365.     - Run the xaaes.cnf startup script.
  366. */
  367.  
  368. const XA_WIDGET_LOCATION sys_menu_loc={LT,2,2};
  369.  
  370. short main(short argc, char *argv[])
  371. {
  372.     short work_in[12];
  373.     short work_out[58];
  374.     char a1[10];
  375.     short f,junk;
  376.     long dummy;
  377.     XA_WIDGET_TREE *menu;
  378. #if DODGY_MEMORY_PROTECTION
  379.     short proc_handle;
  380.     long protection;
  381. #endif
  382.  
  383.     work_in[0]=1;
  384.     for(f=1;f<10; work_in[f++]=1);
  385.     work_in[10]=2;
  386.  
  387. /* Check that MiNT is actually installed */
  388.     if(!GetCookie((long)'MiNT',&dummy))
  389.     {
  390.         BootMessage();
  391.         /* Use puts here, as everything is not yet initialised */
  392.         puts("Sorry, XaAES requires MiNT to run.");
  393.         exit(1);
  394.     }
  395.  
  396. /* Let's get our MiNT process id being's as MiNT is loaded... */
  397.     AESpid=Pgetpid();
  398.     clients[AESpid].cmd_name="XaAES";
  399.  
  400. /* Change the protection mode to OS_SPECIAL to allow operation with
  401.  * memory protection (doesn't work yet, what's wrong?)
  402.  */
  403. /* Craig's Note: I think this causes a massive memory leak in the MiNT kernal, so
  404.    I've disabled it */
  405.  #if DODGY_MEMORY_PROTECTION
  406.     {
  407. #ifndef F_PROT_S
  408. #define F_PROT_S        0x20
  409. #endif
  410. #ifndef F_OS_SPECIAL
  411. #define F_OS_SPECIAL    0x8000
  412. #endif
  413.         /*    Opening "u:\proc\.-1" opens the current process... */
  414.         if ((dummy = Fopen("u:\\proc\\.-1", O_RDONLY)) >= 0)
  415.         {
  416.             proc_handle = (short)dummy;
  417.             Fcntl(proc_handle, &protection, PGETFLAGS);
  418.             protection &= ~0xf0;
  419.             protection |= F_OS_SPECIAL | F_PROT_S;
  420.             Fcntl(proc_handle, &protection, PSETFLAGS);
  421.             Fclose(proc_handle);
  422.         }
  423.     }
  424. #endif
  425.  
  426. /* Where were we started? */
  427.     XaAES_home_drv=Dgetdrv();
  428.     Dgetcwd(XaAES_home,XaAES_home_drv+1,sizeof(XaAES_home)-1);
  429.  
  430. /* Are we an auto/mint.cnf launched program? */
  431.     /* Note: global[0] (AES version number) is initially zero. */
  432.     appl_init();
  433.     auto_program=(global[0]==0);    /* global[0] still zero? */
  434.     
  435.     
  436.     if (auto_program)
  437.     {
  438.         printf("auto program\n");
  439.  
  440.         if ( (Kbshift(-1)&3) && Getrez()==0 )             /* any shift key and low rez */
  441.         {
  442.             Setscreen((void*)-1L,(void*)-1L,1);         /* switch to medium rez */
  443.         }else{
  444.             printf("argc=%d\n",argc);
  445.             for(f=0; f<argc; f++)
  446.                 printf("argv[%d]=%s\n",f,argv[f]);
  447.                 
  448.             /* Set video mode from command line parameter ?*/
  449.             if (argc==3)
  450.             {
  451.                 printf("got 3 args\n");
  452.                 if (!strcmp("-video",argv[1]))             /* Video mode switch */
  453.                 {
  454.                     printf("Requested video mode %s\n",argv[2]);
  455.                     
  456.                     if(GetCookie((long)'_VDO',&dummy))    
  457.                     {
  458.                         if (dummy>=0x00030000L)            /* Check for falcon video */
  459.                         {
  460.                             short modecode=falcon_modes[atoi(argv[2])];
  461.                             CGVsetScreen(modecode);
  462.                         }
  463.                     }
  464.                     
  465.                 }
  466.             }
  467.         }
  468.         v_opnwk(work_in,&P_handle,work_out);            /* If we are an auto program we must open a physical workstation to the screen */
  469.  
  470.     }else{
  471.         P_handle=graf_handle(&junk,&junk,&junk,&junk);    /* The GEM AES has already been started,  */
  472.                                                         /*  so get the physical workstation handle from it */
  473.     }
  474.  
  475. /* Setup the kernal OS call jump table */
  476.     setup_k_function_table();
  477.  
  478. /* Create a whole wodge of semphores for everything from remembering your mothers birthday
  479.    to avoiding an IRA bomb up your arse at work......(yes folks, I work in London and
  480.    don't like getting blown up). */
  481.     Psemaphore(0,APPL_INIT_SEMAPHORE,0);
  482.     Psemaphore(0,TRAP_HANDLER_SEMAPHORE,0);
  483.     Psemaphore(0,WIN_LIST_SEMAPHORE,0);
  484.     Psemaphore(0,ROOT_SEMAPHORE,0);
  485.     Psemaphore(0,CLIENTS_SEMAPHORE,0);
  486.     Psemaphore(0,UPDATE_LOCK,0);
  487.     Psemaphore(0,MOUSE_LOCK,0);
  488.  
  489. /* Print a text boot message */
  490.     BootMessage();
  491.  
  492. /* Patch the AES trap vector to use our OS. */
  493.     hook_into_vector();
  494.  
  495. /* Create the XaAES.cmd introduction pipe */
  496.     AES_in_pipe=Fopen("u:\\pipe\\XaAES.cmd",O_CREAT|O_RDWR);
  497.  
  498. /* Open the u:/dev/console device to get keyboard input */
  499.     KBD_device=Fopen("u:\\dev\\console",O_RDONLY);
  500.     if (KBD_device<0)
  501.     {
  502.         printf("XaAES ERROR: Can't open /dev/console ?\n");
  503.         Cleanup() ;
  504.         return 1;
  505.     }
  506.  
  507. /* Initialise the client descriptors */
  508.     for(f=0; f<MAX_PID; f++)
  509.     {
  510.         clients[f].clnt_pipe_rd=clients[f].clnt_pipe_wr=0;
  511.         clients[f].std_resource=NULL;
  512.         clients[f].parent=AESpid;
  513.         clients[f].cmd_tail=(char*)dummy_cmd_tail;
  514.         clients[f].cmd_name=(char*)dummy_cmd_name;
  515.         clients[f].zen=NULL;
  516.         clients[f].desktop=NULL;
  517.     }
  518.  
  519. /* Open us a virtual workstation for XaAES to play with */
  520.     V_handle=P_handle;
  521.     v_opnvwk(work_in,&V_handle,work_out);
  522.     vswr_mode(V_handle,MD_TRANS);    /* We run in TRANSPARENT mode for all AES ops (unless requested otherwise) */
  523.     vst_alignment(V_handle,0,5,&f,&f);
  524.  
  525. /*     Setup the display parameters */
  526.     display.x=display.y=0;
  527.     display.w=work_out[0];
  528.     display.h=work_out[1];
  529.     display.colours=work_out[13];
  530.     display.display_type=D_LOCAL;
  531.     display.P_handle=P_handle;
  532.     display.V_handle=V_handle;
  533.  
  534.     display.dial_colours=
  535.         (display.colours<16) ?    bw_default_colours : default_colours;
  536.     
  537.     vq_extnd(V_handle,1,work_out);    /* Get extended information */
  538.     display.planes=work_out[4];        /* number of planes in the display */
  539.  
  540. /* If we are using anything apart from the system font for windows, better check 
  541.    for GDOS and load the fonts. */
  542.     if (STANDARD_AES_FONTID!=1)        
  543.     {
  544.         if (vq_gdos())        /* Yeah, I know, this is assuming the old-style vq_gdos() binding */
  545.             vst_load_fonts(V_handle,0);
  546.     }
  547.  
  548. /* Set standard AES font */
  549.     display.standard_font_id = display.small_font_id =
  550.         vst_font(V_handle,STANDARD_AES_FONTID);
  551.  
  552. /* Select Small font */
  553.     display.small_font_point = vst_point(V_handle,
  554.         SMALL_FONT_POINT, &f, &display.small_font_height, &f, &f);
  555.         
  556. /* Select standard font */
  557.      display.standard_font_point = vst_point(V_handle,
  558.          (display.h<=280) ? 9 : STANDARD_FONT_POINT,
  559.         &f, &display.standard_font_height,
  560.         &f, &f);
  561.  
  562. /* Get font information for use by the resource loader */
  563.     vqt_attributes(V_handle, work_out) ;
  564.     display.c_max_w=work_out[8];    /* character cell width */
  565.     display.c_max_h=work_out[9];    /* character cell height */
  566.  
  567. /* Fix up the window widget bitmaps and any others we might be using
  568.    (calls vr_trnfm() for all the bitmaps) */
  569.     fix_bitmaps();
  570.  
  571. /* Set the default clipboard */
  572.     strcpy(scrap_path,"c:\\clipbrd\\");
  573. /* Set the default accessory path */
  574.     strcpy(acc_path,"c:\\");
  575.  
  576. /* Spawn the mouse server */
  577.     MOUSE_in_pipe=(int)Fopen("u:\\pipe\\mouse.XA", O_CREAT|O_RDWR);    /* kernals end of pipe mouse packet pipe */
  578. #if 0
  579.     sprintf(a1,"%d",V_handle);
  580. #else
  581.     sprintf(a1,"%d",P_handle);
  582. #endif
  583.     mouse_pid=Pvfork();
  584.     if (!mouse_pid)
  585.     {                /* In child here */
  586.         execl("mousesrv.tos","mousesrv",a1,NULL);
  587.     }
  588.  
  589. #if SHOW_LOGO_AT_STARTUP
  590. /* Display the XaAES logo */
  591.     if (!Pvfork())
  592.     {                /* In child here */
  593.         execl("logo.prg","XaAES_LOGO",NULL);
  594.     }
  595. #endif
  596.  
  597. /* Parse the standard startup file xaaes.cnf
  598.    This can run programs & re-direct the debugging output to another file/device */
  599. #if GENERATE_DIAGS
  600.     strcpy(debug_path,"debug.list");    /* By default debugging output goes to the file "./debug.list"*/
  601. #endif
  602.     parse_cnf();
  603.  
  604. #if GENERATE_DIAGS
  605. /* Open a diagnostics file? All console output can be considered diagnostics, so
  606.    I just redirect the console to the required file/device */
  607.     debug_file=(int)Fopen(debug_path,O_CREAT|O_WRONLY);
  608.     Fforce(1,debug_file);
  609.  
  610.     DIAGS(("\n\n\nDebug to %s\n",debug_path));
  611. #endif
  612.  
  613.     DIAGS(("Display Device: P_handle=%d, V_handle=%d\n",P_handle,V_handle));
  614.     DIAGS((" size=[%d,%d], colours=%d, bitplanes=%d\n",display.w,display.h,display.colours,display.planes));
  615.  
  616. /* Load the system resource file (we can probably embed this later) */
  617.     system_resources=LoadResources("system.rsc",DU_RSX_CONV, DU_RSY_CONV);
  618.     if (system_resources)
  619.     {
  620.         DIAGS(("system_resources=%lx\n",system_resources));
  621.     }else{
  622.         puts("ERROR: Cann't find/load system resource file 'system.rsc'\n");
  623.         Cleanup();
  624.         return -1;
  625.     }
  626.     
  627. /* Create the root (desktop) window 
  628.     - we don't want messages from it, so make it a NO_MESSAGES window */
  629.     root_window=create_window(AESpid, NO_MESSAGES, 0, 0, display.w, display.h);
  630.     root_window->handle=0;
  631.     root_window->is_open=TRUE;                /* Flag window as open    */
  632.  
  633. /* Tack a menu onto the root widget */
  634.     clients[AESpid].std_menu=ResourceTree(system_resources,SYSTEM_MENU);
  635.     fix_menu(clients[AESpid].std_menu);
  636.     set_menu_widget(root_window, sys_menu_loc, clients[AESpid].std_menu);
  637.     menu=(XA_WIDGET_TREE*)(root_window->widgets[XAW_MENU].stuff);
  638.     menu->owner=AESpid;
  639.  
  640. /* Set a default desktop */
  641.     set_desktop(ResourceTree(system_resources,DEF_DESKTOP));
  642.     (desktop+DESKTOP_LOGO)->ob_x=(root_window->ww-(desktop+DESKTOP_LOGO)->ob_width)/2;
  643.     (desktop+DESKTOP_LOGO)->ob_y=(root_window->wh-(desktop+DESKTOP_LOGO)->ob_height)/2;
  644.     clients[AESpid].desktop=desktop;
  645.  
  646. /* Display the root window */
  647.     v_hide_c(V_handle);
  648.     display_non_topped_window(root_window,NULL);
  649.  
  650. /* Initial iconified window coords */
  651.     iconify_w=ICONIFIED_W; iconify_h=ICONIFIED_H;
  652.     iconify_x=0;
  653.     iconify_y=display.y+display.h-iconify_h-1;
  654.  
  655. /* Turn on the mouse cursor */
  656.     v_show_c(V_handle,0);
  657.  
  658. /* Set our process priority - a high negative value here improves performance a lot, 
  659.    so I set it to -20 in XA_DEFS.H. This doesn't hurt the rest of the systems performance,
  660.    as there are no busy wait loops in the server, and it spends most of it's time blocked
  661.    waiting for commands. */
  662.  
  663.     Pnice(AES_PRIORITY);
  664.  
  665. /* Catch SIGCHLD to spot dead children */
  666.     Psignal(SIGCHLD, (long)HandleSIGCHLD);
  667.  
  668. /* Load Accessories */
  669.     load_accs();
  670.     
  671. /* Catch SIGINT and SIGQUIT so we can shutdown with CTRL+ALT+C */
  672.     Psignal(SIGINT, (long)HandleSIGINT);
  673.     Psignal(SIGQUIT, (long)HandleSIGINT);
  674.  
  675. /* Call the main command interpreter kernal */
  676.     kernal();
  677.  
  678. /* Closedown & exit */
  679.     Cleanup() ;
  680.  
  681.     return 0;
  682. }
  683.